package com.ruoyi.test.mybatisplus;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
// 注入方法类
public class DeleteAll extends
        AbstractMethod {


    protected DeleteAll(String methodName) {
        super(methodName);
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?>
                                  mapperClass, Class<?> modelClass,
                          TableInfo tableInfo) {
        //定义sql语句
        String sql = "delete from " +
                tableInfo.getTableName();;
        //方法名
        String method = "deleteAll";
        //构建SqlSource,它负责将Sql传递到数据库
        SqlSource sqlSource =
                this.languageDriver.createSqlSource(this.configuration,sql,modelClass);
        //构建删除方法
        return
                this.addDeleteMappedStatement(mapperClass,
                        method,sqlSource);
    }
}